package airthmetic.exercise.bit;

public class _190_颠倒二进制位 {
    public int reverseBits(int n) {

        int res = 0;
        for(int i=0; i<32; i++){
            res = (res << 1) + (n & 1);
            n = n>>1;
        }

        return res;
    }


    public int reverseBits2(int n) {
        int res = 0;

        for(int i=0; i<32; i++){
            res ^= (n & (1<<i)) !=0 ? (1<<(31-i)) : 0;
        }
        return res;
    }

    public static void main(String[] args) {
        _190_颠倒二进制位 v = new _190_颠倒二进制位();
        System.out.println(v.reverseBits(1));
    }
}
